<!--
 * @Descripttion: Descripttion
 * @Author: Lzz
 * @Date: 2025-02-15 13:13:50
 * @LastEditors: Lzz
 * @LastEditTime: 2025-02-15 13:57:54
-->
<template>
    <div class="app-container" ref="transportTerms">
        <el-card class="operate-container" shadow="never">
            <i class="el-icon-tickets"></i>
            <span>运输条款</span>
            <el-button type="primary" style="float: right;" @click="handleDialogConfirm()" size="small">保存</el-button>
        </el-card>
        <div class="table-container" v-if="tinymceWidth>0">
            <tinymce :width="tinymceWidth" :height="tinymceHeight" v-model="clauseText"></tinymce>
        </div>
    </div>
</template>
<script>
import { fetchList, updateTransClasuseSetting,getTransClasuseSetting } from '@/api/banner';
import { formatDate } from '@/utils/date';
  import Tinymce from '@/components/Tinymce'
const defaultListQuery = {
    pageNum: 1,
    pageSize: 10,
    resourceName: null,
    resourceUrl: null,
    resourceCategoryId: null
};
const defaultResource = {
    id: null,
    name: null,
    url: null,
    categoryId: null,
    description: ''
};
export default {
    name: 'resourceList',
    data() {
        return {
            clauseText:"",
            listQuery: Object.assign({}, defaultListQuery),
            list: null,
            total: null,
            listLoading: false,
            dialogVisible: false,
            isEdit: false,
            defaultCategoryId: null,
            tinymceWidth:0,
            tinymceHeight:0
        }
    },
    created() {
        this.getList();
    },
   mounted(){
    this.tinymceWidth=this.$refs.transportTerms.clientWidth-40
    this.tinymceHeight=document.documentElement.clientHeight-350
   },
    components:{
        Tinymce
    },
    methods: {
        handleResetSearch() {
            this.listQuery = Object.assign({}, defaultListQuery);
        },
        handleSearchList() {
            this.listQuery.pageNum = 1;
            this.getList();
        },
        handleSizeChange(val) {
            this.listQuery.pageNum = 1;
            this.listQuery.pageSize = val;
            this.getList();
        },
        handleCurrentChange(val) {
            this.listQuery.pageNum = val;
            this.getList();
        },
        handleAdd() {
            this.dialogVisible = true;
            this.isEdit = false;
            this.resource = Object.assign({}, defaultResource);
            this.resource.categoryId = this.defaultCategoryId;
        },
        handleDelete(index, row) {
            this.$confirm('是否要删除该运输条款?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                deleteBanner(row.id).then(response => {
                    this.$message({
                        type: 'success',
                        message: '删除成功!'
                    });
                    this.getList();
                });
            });
        },
        handleUpdate(index, row) {
            this.dialogVisible = true;
            this.isEdit = true;
            this.resource = Object.assign({}, row);
            delete this.resource.createTime
            delete this.resource.createBy
            delete this.resource.updateTime
            delete this.resource.updateBy
        },
        handleDialogConfirm() {
            updateTransClasuseSetting({
                "clauseText":this.clauseText
            }).then(res => {
                        this.$message({
                            message: '保存成功！',
                            type: 'success'
                        });
                    })
        },
        handleShowCategory() {
            this.$router.push({ path: '/ums/resourceCategory' })
        },
        getList() {
            this.listLoading = true;
            getTransClasuseSetting().then(res=>{
                this.listLoading = false;
                this.clauseText = res.data.clauseText
                console.log("init", this.clauseText )
            })
        },
    }
}
</script>
<style></style>